// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   JobtypeUICheck.java

package nc.ui.bd.b36;

import java.awt.Container;
import nc.bs.logging.Logger;
import nc.bs.uap.bd.BDException;
import nc.bs.uap.bd.BDRuntimeException;
import nc.ui.ml.NCLangRes;
import nc.ui.trade.check.BeforeActionCHK;
import nc.vo.bd.MultiLangTrans;
import nc.vo.bd.b36.JobtypeVO;
import nc.vo.ml.AbstractNCLangRes;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.trade.checkrule.*;
import nc.vo.util.tree.LevelTool;

public class JobtypeUICheck extends BeforeActionCHK
	implements ICheckRules, IUniqueRules
{

	AggregatedValueObject m_vo;

	public JobtypeUICheck()
	{
		m_vo = null;
	}

	public JobtypeUICheck(AggregatedValueObject vo)
	{
		m_vo = null;
		m_vo = vo;
	}

	public IUniqueRule[] getHeadUniqueRules()
	{
		return null;
	}

	public IUniqueRule[] getItemUniqueRules(String tablecode)
	{
		String uniqueFields[] = {
			"jobphasecode"
		};
		String errorMsg = MultiLangTrans.getTransStr("MC1", new String[] {
			NCLangRes4VoTransl.getNCLangRes().getStrByID("10081402", "UPP10081402-000007"), null
		});
		UniqueRule itemUniqueRule = new UniqueRule(errorMsg, uniqueFields);
		return (new IUniqueRule[] {
			itemUniqueRule
		});
	}

	public ICheckRule[] getHeadCheckRules()
	{
		Integer minLevel = null;
		Integer maxLevel = null;
		if (m_vo != null && m_vo.getParentVO() != null)
		{
			JobtypeVO jobtype = (JobtypeVO)m_vo.getParentVO();
			if (jobtype.getJobclclass() != null && jobtype.getJobclclass().trim().length() > 0)
			{
				LevelTool lt = new LevelTool(100, 200);
				try
				{
					lt.checkString(jobtype.getJobclclass());
					maxLevel = new Integer(lt.getCurrentLevelCount());
					minLevel = new Integer(0);
				}
				catch (BusinessException e)
				{
					Logger.error(e.getMessage(), e);
					throw new BDRuntimeException(e.getMessage());
				}
			}
		}
		return (new ICheckRule[] {
			new CheckRule(NCLangRes.getInstance().getStrByID("10081402", "UPP10081402-000014"), "jobtypename", false, null, null), new CheckRule(NCLangRes.getInstance().getStrByID("10081402", "UPP10081402-000015"), "jobtypecode", false, null, null), new CheckRule(NCLangRes.getInstance().getStrByID("10081402", "UPP10081402-000020"), "jobclclass", false, null, null), new CheckRule(NCLangRes.getInstance().getStrByID("10081402", "UPP10081402-000019"), "controlnum", false, minLevel, maxLevel)
		});
	}

	public ICheckRule[] getItemCheckRules(String tablecode)
	{
		return (new ICheckRule[] {
			new CheckRule(NCLangRes.getInstance().getStrByID("10081402", "UPP10081402-000007"), "jobphasecode", false, null, null), new CheckRule(NCLangRes.getInstance().getStrByID("10081402", "UPP10081402-000008"), "jobphasename", false, null, null)
		});
	}

	public ICompareRule[] getHeadCompareRules()
	{
		return null;
	}

	public String[] getHeadIntegerField()
	{
		return null;
	}

	public String[] getHeadUFDoubleField()
	{
		return null;
	}

	public ICompareRule[] getItemCompareRules(String tablecode)
	{
		return null;
	}

	public String[] getItemIntegerField(String tablecode)
	{
		return null;
	}

	public String[] getItemUFDoubleField(String tablecode)
	{
		return null;
	}

	public void runBatchClass(Container container, String s, String s1, AggregatedValueObject aaggregatedvalueobject[], Object aobj[])
		throws Exception
	{
	}

	private void checkBodyIsNull(AggregatedValueObject vo)
		throws Exception
	{
		if (vo == null || vo.getParentVO() == null)
			return;
		JobtypeVO parent = (JobtypeVO)vo.getParentVO();
		if (parent.getJobphaseflag() != null && parent.getJobphaseflag().booleanValue() && (vo.getChildrenVO() == null || vo.getChildrenVO().length == 0))
			throw new BDException(MultiLangTrans.getTransStr("MC3", new String[] {
				NCLangRes.getInstance().getStrByID("10081402", "UPP10081402-000004")
			}));
		else
			return;
	}

	public void runClass(Container parent, String billType, String actionName, AggregatedValueObject vo, Object obj)
		throws Exception
	{
		if (actionName.equals("WRITE"))
		{
			if (!VOChecker.check(vo, new JobtypeUICheck(vo)))
				throw new BusinessException(VOChecker.getErrorMessage());
			checkBodyIsNull(vo);
		}
	}
}
